package top.mccat.raven.item;

import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.ItemMeta;
import top.mccat.raven.dao.OnStrengthItem;
import top.mccat.raven.utils.handler.StrengthCommandHandler;
import top.mccat.raven.utils.utils.ColorUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: StrengthItem
 * @Description: 武器强化
 * @Author: Raven
 * @Date: 2021/7/7
 * @Version: 1.0
 */
public class MyItem extends StrengthItem implements OnStrengthItem {
    private ItemStack strengthStack;
    private Player player;
    private PlayerInventory inventory;

    public MyItem(Player player) {
        super(player.getInventory().getItemInMainHand());
        this.player = player;
        inventory = player.getInventory();
        strengthStack = getStrengthStack();
    }
    public MyItem(Player player, ItemStack stack){
        super(stack);
        this.player = player;
        inventory = player.getInventory();
        strengthStack = getStrengthStack();
    }

    @Override
    public ItemStack getStrengthstack(StrengthItem myItem,String color,int level) {
        ItemStack stack = myItem.getStrengthStack();
        ItemMeta meta = myItem.getStrengthMeta();
        List<String> strenghtLore;
        strenghtLore = new ArrayList<>();
        color = ColorUtils.getColorStr(color);
        if(level > 0){
            strenghtLore.add(ColorUtils.getColorStr(StrengthCommandHandler.Title));
            StringBuffer buffer = new StringBuffer(color);
            if(level == 30){
                strenghtLore.add(ColorUtils.getColorStr(color+FULLLEVEL));
                strenghtLore.add(ColorUtils.getColorStr(color+FULLLEVEL));
                strenghtLore.add(ColorUtils.getColorStr(color+FULLLEVEL));
            }else if(level>20){
                strenghtLore.add(ColorUtils.getColorStr(color+FULLLEVEL));
                strenghtLore.add(ColorUtils.getColorStr(color+FULLLEVEL));
                for(int i=0;i<level-20;i++){
                    buffer.append("✡");
                }
                strenghtLore.add(buffer.toString());
            }else if(level>10){
                strenghtLore.add(ColorUtils.getColorStr(color+FULLLEVEL));
                for(int i=0;i<level-10;i++){
                    buffer.append("✡");
                }
                strenghtLore.add(buffer.toString());
            }else {
                for(int i=0;i<level;i++){
                    buffer.append("✡");
                }
                strenghtLore.add(buffer.toString());
            }
        }else {
            strenghtLore.add(ColorUtils.getColorStr(StrengthCommandHandler.Title));
            strenghtLore.add(color+"✡");
        }
        strenghtLore.add(StrengthItem.endLore);
        if(strenghtLore != null){
            meta.setLore(strenghtLore);
        }
        stack.setItemMeta(meta);
        return stack;
    }

    public PlayerInventory getInventory() {
        return inventory;
    }
}
